<template>
<!--    <a @click="append(data)"><i class="el-icon-folder-add" v-if="data.children != null"></i></a>-->
    <a @click="dialogVisible = true"><i class="el-icon-folder-add"></i></a>

    <el-dialog
            v-model="dialogVisible"
            title="新增文件夹"
            width="30%"
    >

        <el-form :model="form">
            <el-form-item label="文件夹" :label-width="formLabelWidth">
                <el-input v-model="form.folderName" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="addFolder"
        >确认</el-button
        >
      </span>
        </template>
    </el-dialog>
</template>

<script>
    import { defineComponent, ref } from 'vue'
    import {addFileFolder} from '../api/file'
    import {ElMessage} from 'element-plus'

    export default defineComponent({
        name: "AddFolder",
        data() {
            return {
                form:{
                    folderName: ''
                },
                formLabelWidth: '80px',
            }
        },
        emits: ['add'],
        props: {
            fileFolder: {
                type: String,
                required: true
            }
        },
        methods:{
            addFolder(){
                this.dialogVisible = false;
                console.log(this.fileFolder + "/" +this.form.folderName);
                addFileFolder({"dirName":this.fileFolder + "/" +this.form.folderName})
                    .then(ref => {
                        if(ref.data.code == 200){
                            ElMessage.success("添加成功")
                        }else{
                            ElMessage.error("添加失败")
                        }
                })
                this.$emit('add')
            }
        },
        setup() {
            const dialogVisible = ref(false)

            return {
                dialogVisible,
            }
        },
    })
</script>
